<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="lushu">
		<title>单位帐户汇总</title>
		<script language="javascript" type="text/javascript" src="../script/print.js"></script>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
			var Page;
			//var distribute = false;
			function initPageElements(){
				Page.readonlyTableStyle = 'col2 label6';
				Page.distribute = false;
				Page.templateItems = [
										["name","姓名"]
										,["deptName","部门"]
										,["asn","卡号"]
										,["cardStatus","卡 状 态"]
										,["cardUserUnique","客户编号"]
										,["cardUserStatus","客户状态"]
										,["balance","帐户余额","right"]
										,["amount","模板汇总额","right"]
										,["realAmount","实际汇总额","right"]
									];
				Page.initOperationForm = function(result){
					if (result.cardUser.type!=CardUserType.COMPANY || !result.companyCustomer){
						showWarning("不是单位主卡,不能汇总");
						return false;
					}
					Page.byBalance = false;
					Common.initDict(Page.operationForm.accCode,TX.AccountType.userTx());
					return true;
				}
				Page.changeAccCode = function(){
					TX.Template.list();
				}
				Page.templateFilter = function(){
					var amount = 0;
					for (x in Page.templateAmounts){
						if (Page.templateAmounts[x] && typeof(Page.templateAmounts[x])!='function'){
							var v = Page.templateAmounts[x];
							if (v.cardUserStatus!=CardUserStatus.OK)
								delete(Page.templateAmounts[x]);
							else{
								if (Page.byBalance || v.amount>v.balance)
									Page.templateAmounts[x].realAmount = v.balance;
								else
									Page.templateAmounts[x].realAmount = v.amount;
								amount += Page.templateAmounts[x].realAmount;
							}
						}
					}
					Page.operationForm.amount.value = Account.Transformer.OutByAccCode(Page.accCode)(amount);
				}
			}
			function setCollectionType(byBalance){
				Page.byBalance = byBalance;
				TX.Template.load();
//				if(byBalance){
//					alert(1)
//				}else{
//					alert(2)
//				}
			}
			//汇总
			function doTransfer(collectAll){
				var count = 0;
				var detailAmount = [];
				for (x in Page.templateAmounts){
					var da = Page.templateAmounts[x];
					if (typeof da!="function" && da){
						detailAmount.push(da.cardUserUnique + "_" + (collectAll?0:da.realAmount));
						count++;
					}
				}
				if (count==0){
					showWarning("没有需要汇总的帐户");
					return;
				}
				if(!collectAll){
					if (Page.operationForm.amount.value ==0){
						showWarning("汇总额为0");
						return;
					}
				}
				var confirmString =   "单位帐户编号:" + Page.userInfo.cardUser.uniqueId + TX.SHOW_INFO_LINEBREAK
									+ "帐 户 类 型:" + Common.getText('account_type',Page.accCode) + TX.SHOW_INFO_LINEBREAK
									+ "帐 户 单 位:" + Page.operationForm.unit.value + TX.SHOW_INFO_LINEBREAK
									+ "汇 总 总 额:" + Page.operationForm.amount.value + TX.SHOW_INFO_LINEBREAK
									+ "总共汇总帐户: "+ count + "个" + TX.SHOW_INFO_LINEBREAK + TX.SHOW_INFO_LINEBREAK
									+ "注意：只有司机客户在正常状态下才能参与汇总，同时当帐户内余额低于汇总额时，系统会按照余额进行汇总。故实际汇总总额可能和模板有差异，以实际交易结果为准。";
				if(showQuestion(confirmString,300,400)){
					DWR.call("tradeService.batchTransfer",
						Page.userInfo.cardUser.uniqueId,
						detailAmount.join(','),
						Page.distribute,
						Page.accCode,
						function(result){
							showInformation("汇总成功!");
//							switchPage("searchFormDiv");
							Eui.getBillHtml('content',{queryName:'transfer_list',
													uniqueId:Page.userInfo.cardUser.uniqueId,
													batchNo:result});
							switchPage("billDiv");
							//调用打印接口
							WebPrint.print('content')
						},
						{blockScreen:true}
					);
				}
			}
		</script>
	</head>
	<body onload="TX.NoCardTrade.init()">
		<div class="nav"><div id="nav">&nbsp;</div></div>

		<div id="searchFormDiv">	
			<div class="form">
				<div class="formTitle">请输入单位帐户的相关信息</div>
				<form id='searchForm' name="searchForm">
					<input type="hidden" name="asn">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0" align="center">
						<tr>
							<td>
								<label>客户编号</label> 
								<input type="text" size="22" name="cardUserUnique" value="" maxlength="18" onblur="checkV(this,'uniqueId',true)">
							</td>
							<td><button name="search" onclick="TX.NoCardTrade.getUserAccountInfo()">查  询</button></td>
						</tr>
					</table>
				</form>
			</div>
		</div>

		<div id="operationFormDiv" style="display:none;">
			<form id="operationForm" name="operationForm">
				<div class="form">
					<div class="formTitle">单位帐户汇总</div>	
						<span id="readonlyInfo"></span>
						<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
							<tr>
								<td><label>帐户类型</label> <select name="accCode" onchange="TX.NoCardTrade.changeAccCode(this)"><option></option></select></td>
								<td><label>汇 总 额</label> <input type="text" name="amount" readonly class="readonly"></td>
							</tr>
							<tr>
								<td>
									<label>汇总模板</label> 
									<select name="templateId" onchange="TX.Template.load()"><option></option></select>
									<button onclick="TX.Template.open()">模板维护</button>
									</td>
								<td><label>模板保存时间</label> <input type="text" name="templateTime" readonly class="readonly"></td>
							</tr>
						</table>
				</div>
				<p>
					<input type="checkbox" id="" onclick="setCollectionType(this.checked)">根据实际余额汇总
					<button id="operation" onclick="doTransfer()">汇 总</button>
					<button onclick="TX.NoCardTrade.goFirstPage()">返 回</button>
				</p>
			</form>
			<div class="form" id="templateDetailsDiv">
				<div class="formTitle">汇总对象明细列表</div>
				<div id="templateDetails"></div>
			</div>
		</div>
				
		<div id="printSheetDiv" style="display:none;">
			<div class="form">
				<div class="formTitle">单位备用金汇总明细</div>
				<div id="mainTrade"></div>
			</div>
		</div>
		<div id="billDiv" class="form" width="100% " style="display:none;">
			<div class="formTitle">
				<div class="l">交易明细</div>
				<div class="r">
					<button onclick="WebPrint.preview('content')">打印预览</button>
			 		<button onclick="WebPrint.print('content')">打印</button>
			 		<button onclick="TX.NoCardTrade.goFirstPage()">返 回</button>
				</div>
			</div>
			<div  id="content"  align='center'></div>
		</div>
	</body>
</html>